/*
 * @Author: Donald duck tang5722917@163.com
 * @Date: 2024-06-03 11:20:37
 * @LastEditors: Donald duck tang5722917@163.com
 * @LastEditTime: 2024-06-28 18:58:59
 * @FilePath: \mysticism-mud\lpc_atest\lpc_atest.c
 * @Description: 
 * Copyright (c) 2024 by Donald duck email: tang5722917@163.com, All Rights Reserved.
 */
#include "lpc_atest.h"

//log等级
#ifndef ATEST_LOG_RANK
#define ATEST_LOG_RANK   2
#endif


#define ATEST_LOG_OB  load_object(LPC_ATEST_PATH "lpc_atest_log")

//取得目录信息
string * get_test_dir(string path){
    string * dir;
    int i;
    mixed * result;
    dir = get_dir(path);
    i = sizeof(dir);
    result = ({path});
    if(i <= 0) return copy(({path}));
    else{
        foreach(string d in dir)
        {
            if(file_size(path + d + "/") == -2){
                result += ({get_test_dir(path + d + "/")});
            }
            else{
                result += ({d});
            }
        }
    }
    return copy(result);
}

Test_Info run_test_file(string file)
{
    object test_ob;
    string * result_info;
    int result;
    string info;
    Test_Info test;
    test_ob = new(file);
    test_ob->main();
    result_info = test_ob->get_result_info();
    result = test_ob->get_result();
    info = test_ob->get_test_info();
    test = new(Test_Info,result:result,result_info:result_info,info:info,test_ob:test_ob);
    return test;
}

string * run_test(string file){
    Test_Info test_result;
    if((file[0..4] != "test_") && file[strlen(file)-2 ..strlen(file)-1] != ".c")
        return 0;
    else{
        test_result = run_test_file(file);
        if(classp(test_result))
            return ({file,test_result});
        else return 0;
    }
}

string * run_all_dir(string * dir)
{
    mixed result_info = ({});
    mixed dir_d,info;
    string path_name = dir[0];
    dir_d = dir - ({dir[0]});
    foreach(mixed d in dir_d){
        if(arrayp(d)) result_info +=  run_all_dir(d);
        else{
            info = run_test(path_name + d);
            if(info != 0)
                result_info += info;
        }
    }
    return copy(result_info);
}

//完成所有测试
varargs void test_all(string log_path){
    mixed * dir = get_test_dir(ATEST_PATH);
    mixed * test_result = run_all_dir(dir);
    if(ATEST_LOG_OB->write_log(test_result,ATEST_LOG_RANK))
        debug_message("Sucess write log file");
    else debug_message("Write log file fail");
}

//完成名称测试
varargs void test_run(string path, string test_name, string log_path){

}
